package slim3.controller;

import org.slim3.controller.Controller;
import org.slim3.controller.Navigation;
import slim3.utils.AccountUtils;
import com.google.appengine.api.users.UserService;
import com.google.appengine.api.users.UserServiceFactory;

import slim3.service.PostService;

public class IndexController extends Controller {

    private PostService service = new PostService();
    
    @Override
    public Navigation run() throws Exception {
        requestScope("postList", service.getAll());
        UserService userService = UserServiceFactory.getUserService();
        String thisURL = request.getRequestURI();

        boolean isAdmin = AccountUtils.isAdmin(request);
        if (isAdmin) {
            requestScope("logoutInfo", userService.createLogoutURL(thisURL));
            return forward("/admin/Index.jsp");
        }else {
            requestScope("loginInfo", userService.createLoginURL(thisURL));
            return forward("Index.jsp");
        }
        
    }
}
